package com.app.newiptv.promote;


import com.app.newiptv.bean.RequestDto;
import com.app.newiptv.bean.greendao.AppUpdateInfo;
import com.app.newiptv.callback.IRequestLisenter;
import com.app.newiptv.utils.APPLog;
import com.app.newiptv.utils.OkGoUtil;
import com.app.newiptv.utils.Paths;

public class ConfigrationLoader  {
    private Callback callback;

    public void setCallback(Callback callback) {
        this.callback = callback;
    }

    public interface Callback {
        void onError(String code, String msg);

        void onCompleted();

    }

    public void loadConfig(String url){
        OkGoUtil<AppUpdateInfo> okGoUtil = new OkGoUtil<AppUpdateInfo>(AppUpdateInfo.class, OkGoUtil.TYPE_DATA, new IRequestLisenter() {
            @Override
            public void onSuccessData(RequestDto dto) {
                AppUpdateInfo appUpdateInfo = (AppUpdateInfo) dto.getData();
                UpgradeHelper helper = UpgradeHelper.getInstance();
                helper.setVersionCode(appUpdateInfo.getVersionCode());
                helper.setDownloadUrl(Paths.HOSTPATH + appUpdateInfo.getAddress());
                APPLog.printInfo("VersionCode()==>:"+appUpdateInfo.getVersionCode());
                APPLog.printInfo("Address==>:"+ appUpdateInfo.getAddress());
                callback.onCompleted();
            }

            @Override
            public void onErrer(int code, String errMsg) {

            }
        });
        okGoUtil.requestPost(url);
    }

}
